﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CourseSystem.Core.BLL;
using CourseSystem.Core.Entities;

namespace CourseSystem.Common.Helpers
{
    public class ForumsHelper
    {
        public static void CheckTodayCount(ForumsInfo info)
        {
            if (info != null)
            {
                if (info.LastPosterId == 0 || info.LastPostTime.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
                {
                    info.TodayPostCount = 0;
                    info.TodayTopicCount = 0;
                }
            }
        }

        public static bool EditLastUpdate(int fid, bool isTopic = false)
        {
            var info = ForumsBLL.Get(fid);
            if (info == null)
                return false;
            info.LastPosterId = UserHelper.LoginUser.Id;
            info.LastPosterName = UserHelper.LoginUser.UserName;
            info.LastPosterType = UserHelper.GetLoginUserType();
            info.LastPostTime = DateTime.Now;
            if (isTopic)
            {
                info.TopicCount++;
                info.TodayTopicCount++;
            }
            info.TodayPostCount++;
            info.PostCount++;
            return ForumsBLL.Edit(info);
        }
    }
}
